package com.pig4cloud.pig.demo.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pig4cloud.pig.demo.Mapper.UserAndLikeMapper;
import com.pig4cloud.pig.demo.Service.ConlikeService;
import com.pig4cloud.pig.demo.Service.UserAndLikeService;
import com.pig4cloud.pig.demo.feign.Entity.Conlike;
import com.pig4cloud.pig.demo.feign.Entity.Userandlike;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAndLikeServiceImpl implements UserAndLikeService {
    @Autowired
    private UserAndLikeMapper userAndLikeMapper;

    @Autowired
    private ConlikeService conlikeService;

    @Override
    public int insert(Userandlike userAndLike) {
        userAndLike.setIsLiked(1);
        return userAndLikeMapper.insert(userAndLike);
    }

//    @Override
//    public List<Userandlike> findByUid(Long uid, int currentPage, int size) {
//        return userAndLikeMapper.findByUid(uid, currentPage, size);
//    }

    @Override
    public int updateByUidAndCid(Userandlike userandlike) {
        return userAndLikeMapper.updateByUidAndCid(userandlike.getUid(), userandlike.getConlike().getId(), userandlike.getIsLiked());
    }

    @Override
    public Userandlike findByUidAndCid(Long uid, Long cid) {
        Userandlike userandlike = userAndLikeMapper.findByUidAndCid(uid, cid);
        if (userandlike != null)
            return userandlike;

        int insert = userAndLikeMapper.insertByUidAndCid(uid, cid, 0);
        if (insert > 0)
            return userAndLikeMapper.findByUidAndCid(uid, cid);
        return null;
    }
}
